# Contributor: prspkt <prspkt@protonmail.com>
# Maintainer: prspkt <prspkt@protonmail.com>
pkgname=brotli
pkgver=1.0.9
pkgrel=6
pkgdesc="Generic lossless compressor"
url="https://github.com/google/brotli"
arch="all"
license="MIT"
makedepends_build="automake autoconf libtool"
if [ -z "$BOOTSTRAP" ]; then
	makedepends_host="python3-dev"
	python="py3-$pkgname:py3"
fi
subpackages="$pkgname-doc $pkgname-static $pkgname-dev $pkgname-libs $python"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/brotli/archive/v$pkgver.tar.gz
	optimize-mips-s390x.patch
	build-tool-against-shared-lib.patch
	838.patch
	0545759b2ed9b69e3f21fd0ac954bee78f3104b6.patch
	"

# secfixes:
#   1.0.9-r0:
#     - CVE-2020-8927

# use sysroot when cross compiling to avoid libtool pulling in host libs
[ "$CBUILD"  != "$CHOST" ] && _cross_configure="--with-sysroot=$CBUILDROOT"

prepare() {
	default_prepare
	sed -i 's,/usr/bin/env bash,/bin/sh,' tests/*.sh
	sh ./bootstrap
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--target=$CTARGET \
		--prefix=/usr \
		$_cross_configure \
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	local man; for man in docs/*.?; do
		install -D -m644 $man "$pkgdir"/usr/share/man/man${man##*.}/${man##*/}
	done
}

py3() {
	cd "$builddir"
	python3 setup.py install --prefix=/usr --root="$subpkgdir"
}

sha512sums="b8e2df955e8796ac1f022eb4ebad29532cb7e3aa6a4b6aee91dbd2c7d637eee84d9a144d3e878895bb5e62800875c2c01c8f737a1261020c54feacf9f676b5f5  brotli-1.0.9.tar.gz
59e934578ce23b703f8f25f56578f8e9fd1466a9844b6f67b542acd6496df352548e3762697dc3851cfd0f8e1bad170bfdaa3e8a87c901fe81e2f3042e3aee84  optimize-mips-s390x.patch
f4a7653a0f7ef69f059d7f744a48c7731c8e66f977ce2e66cd106f697e82aa1f005923898d216a3d8be143b2dc8db1927c09daedb981818e752640a333d75fbc  build-tool-against-shared-lib.patch
58ef677595f0db80b7d1353e42603cc30ef9b0b9530927f731ee31ac60ad9a3b2aac960a5cd100f8b10e547c9534e1ebf78c53550b52eed6fb3b7fb853317d20  838.patch
6b7953f09c7ce4219dd9411d53fcd495e0de92f210c53be43dcd235a47050b10933b347fcc8e92d7e3fd89b12375eb0deea61b01eb279902079fa7b7aca62a5a  0545759b2ed9b69e3f21fd0ac954bee78f3104b6.patch"
